package com.example.project.projectspringcloud.controller.front.sys;

import com.example.project.projectspringcloud.entity.RespBody;
import com.example.project.projectspringcloud.entity.sys.Dictionary;
import com.example.project.projectspringcloud.service.sys.SysDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = "字典类")
@RequestMapping(value = "/dict")
@Controller
public class DictionaryController {

    @Autowired
    private SysDictionaryService sysDictionaryService;

    @ApiOperation(value = "API获取字典数据", notes = "返回RespBody结构封闭字典数据")
    @GetMapping(value = "/api/list/{type}")
    @ResponseBody
    public RespBody list(@PathVariable("type") String type) throws Exception {
        List<Dictionary> dictionaries = sysDictionaryService.list(new Dictionary(type), null);
        return RespBody.ok(dictionaries);
    }
}
